<%--
  Created by IntelliJ IDEA.
  User: 彭辉明
  Date: 2024/5/23
  Time: 9:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<style>
    body {
        font-family: Arial, sans-serif;
        line-height: 1.6;
        color: #333;
        margin: 0;
        padding: 0;
        background-color: #f7f7f7;
    }
    #allDiv {
        padding: 30px;
        max-width: 800px;
        margin: 0 auto;
    }
    h1 {
        text-align: center;
        margin-bottom: 30px;
        color: #4CAF50;
    }
    table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 30px;
    }
    th, td {
        padding: 12px 15px;
        text-align: left;
        border: 1px solid #ddd;
    }
    th {
        background-color: #4CAF50;
        color: white;
    }
    tr:nth-child(even) {
        background-color: #f2f2f2;
    }
    a {
        color: #4CAF50;
        text-decoration: none;
    }
    a:hover {
        text-decoration: underline;
    }
    #selectById {
        padding: 30px;
        background-color: white;
        border-radius: 5px;
        box-shadow: 0 0 5px rgba(0,0,0,0.1);
        transition: all 1s ease;
    }
    #selectById input[type="text"] {
        width: 100%;
        padding: 10px;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 3px;
        box-sizing: border-box;
    }
    #NoShow {
        background-color: #4CAF50;
        color: white;
        border: none;
        padding: 10px 20px;
        cursor: pointer;
        text-align: center;
        margin-top: 20px;
    }
    #NoShow:hover {
        background-color: #45a049;
    }
</style>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<div id="allDiv">
    <h1>营业网点查询</h1>
    <a href="#" id="newBranches">新增网点</a>
    <table>
        <tr>
            <th>网点名称</th>
            <th>所在城区</th>
            <th>网点地址</th>
            <th>联系电话</th>
            <th>操作</th>
        </tr>
        <tbody id="showBranches"></tbody>
    </table>
</div>
<div id="selectById" style="display: none">
    <h1>网点详细信息</h1>
    网点名称：<input type="text" id="name" disabled><br>
    营业执照编号：<input type="text" id="license" disabled><br>
    所在地区：<input type="text" id="cityArea" disabled><br>
    网点地址：<input type="text" id="address" disabled><br>
    联系电话：<input type="text" id="telephone" disabled><br>
    网点简介：<input type="text" id="introduction" disabled><br>
    <input type="button" value="隐藏信息" id="NoShow">
</div>
</body>
</html>
<script>
    $(function (){
        onloadOk();
    })
    function onloadOk() {
        $.ajax({
            url:'/branches/branches.action',
            type:'post',
            dataType:'json',
            data:{opr:'select'},
            success:function (data) {
                for(var i = 0; i < data.length; i++) {
                    var str = "<tr>";
                    str += "<td>" + data[i].name + "</td>";
                    str += "<td>" + data[i].cityArea + "</td>";
                    str += "<td>" + data[i].address + "</td>";
                    str += "<td>" + data[i].telephone + "</td>";
                    str += "<td><a href='#' onclick='selectBy(\"" + data[i].id + "\")'>查询</a></td>";
                    str += "</tr>";
                    $("#showBranches").append(str);
                }
            },
            error:function (){
                console.log('error')
            }
        })
    }

    function selectBy(id) {
        $('#selectById').show(1000)
        $('#allDiv').hide();
        $.ajax({
            url:'/branches/branches.action',
            type: 'post',
            dataType: 'json',
            data: {opr: 'selectById', id: id},
            success:function (data){
                $('#name').val(data.name)
                $('#license').val(data.businessNo);
                $('#cityArea').val(data.cityArea);
                $('#address').val(data.address);
                $('#telephone').val(data.telephone);
                $('#introduction').val(data.summary);
            },
            error:function (){

            }
        })
    }
    $('#NoShow').on('click',function (){
        $('#name').val(" ")
        $('#license').val(" ");
        $('#cityArea').val(" ");
        $('#address').val(" ");
        $('#telephone').val(" ");
        $('#introduction').val(" ");

        $('#selectById').hide(1000);
        $('#allDiv').show();
    })

    $('#newBranches').on('click',function (){
        window.location.href = 'insertBeanches.jsp'
    })
</script>
